//
//  MessageV.m
//  TT
//
//  Created by Lenny on 16/5/6.
//  Copyright © 2016年 Lenny. All rights reserved.
//

#import "MessageV.h"

@interface MessageV ()

@property(nonatomic,strong)UIView *contentV;

@end

@implementation MessageV

#pragma mark - life cycle

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {

        [self UI];
    }
    return self;
}


#pragma mark - private motheds 
- (void)UI {
    
    UIView *backV = [[UIView alloc] init];
    backV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [self addSubview:backV];
    [backV addSubview:self.contentV];
    
    UIImageView *imageV = [[UIImageView alloc] init];
    imageV.image = [UIImage imageNamed:@"icon_tabbar_m_1_normal"];
    [self.contentV addSubview:imageV];
    UIImageView *aniImgV = [[UIImageView alloc] init];
    aniImgV.animationImages = [self viewsToImage];
    aniImgV.animationDuration = 1;
    [aniImgV startAnimating];
    [self.contentV addSubview:aniImgV];
    
    UILabel *desL = [[UILabel alloc] init];
    desL.text = @"放开手指 即发送信息";
    desL.font = [UIFont systemFontOfSize:12];
    desL.textColor = [UIColor whiteColor];
    [self.contentV addSubview:desL];

    __weak typeof(self) weakSelf = self;
    [backV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.contentV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.center.equalTo(weakSelf);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(150);
    }];
    
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-50);
        make.bottom.mas_equalTo(-30);
    }];
    
    [desL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-10);
        make.centerX.equalTo(weakSelf.contentV);
    }];
    
    [aniImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imageV);
        make.left.equalTo(imageV.mas_right).offset(5);
        make.top.equalTo(imageV.mas_top);
        make.bottom.equalTo(imageV.mas_bottom);
    }];
}

- (NSArray *)viewsToImage {
    
    NSMutableArray *arr = [NSMutableArray array];
    UIView *curV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 100)];
    for (int i = 0; i < 10; i ++) {
        
        UIView *lineV = [[UIView alloc] initWithFrame:CGRectMake(0, (10 - i)* 10, 30, 5)];
        lineV.backgroundColor = [UIColor whiteColor];
        [curV addSubview:lineV];
        [arr addObject:[curV convertViewToImage]];
    }
    return arr;
}

#pragma mark - setters and getters
- (UIView *)contentV {
    
    if (_contentV == nil) {
        _contentV = [[UIView alloc] init];
        _contentV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        _contentV.layer.cornerRadius = 10;
    }
    return _contentV;
}

@end
